package xyz.zhouzhousag.server.common.exception;
/**
 * Description:
 * <p>
 * ClassName: MyExceptionHandler
 * date: 2021/9/26 18:02
 *
 * @author Yin.Liu
 * @version 1.0
 * @since JDK 1.8
 */

import org.apache.shiro.ShiroException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import xyz.zhouzhousag.server.pojo.entity.BaseResponse;

import javax.servlet.http.HttpServletRequest;
/**
 *@ClassName MyExceptionHandler
 *@Description 捕获异常并返回不同异常的错误信息
 *@Author Yin.Liu8
 *@Date 2021/9/26 18:02
 *@Version 1.0
 */
@RestControllerAdvice
public class MyExceptionHandler {
    // 捕捉shiro的异常
    @ExceptionHandler(ShiroException.class)
    public BaseResponse handleShiroException(ShiroException e) {
        return BaseResponse.fail(e.getMessage());
    }

    // 捕捉其他所有异常
    @ExceptionHandler(Exception.class)
    public BaseResponse globalException(HttpServletRequest request, Throwable ex) {
        return BaseResponse.fail(ex.getMessage());
    }
}
